﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Oragon.Architecture.Data.SqlBuilder.Operators
{
    /// <summary>
    /// Representa um operador SQL binário
    /// </summary>
    [Serializable]
    public abstract class BinaryOperator : SQLOperator
    {
        /// <summary>
        /// Representa a expressão à esquerda da sentença
        /// </summary>
        public ISQLStatement LeftExpression { get; set; }
        /// <summary>
        /// Representa a expressão à direita da sentença
        /// </summary>
        public ISQLStatement RightExpression { get; set; }
        /// <summary>
        /// Identifica a operação
        /// </summary>
        public abstract string Operator { get; }

        protected BinaryOperator(ISQLStatement leftExpression, ISQLStatement rightExpression)
        {
            this.LeftExpression = leftExpression;
            this.RightExpression = rightExpression;
        }


        /// <summary>
        /// Retorna o SQL com da operação
        /// </summary>
        public override string ToSQL()
        {
            string leftExpressionSQL = this.LeftExpression == null ? string.Empty : this.LeftExpression.ToSQL();
            string rightExpressionSQL = this.RightExpression == null ? string.Empty : this.RightExpression.ToSQL();
            return string.Format(System.Globalization.CultureInfo.InvariantCulture, "( {0} {1} {2} )", leftExpressionSQL, this.Operator, rightExpressionSQL);
        }

    }
}
